package com.cxq.finalproject.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;


public class TabFragAdapter extends FragmentStateAdapter {
    private List<Class> fragments;
//    private List<Integer> colors;

    public TabFragAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        if (fragments == null)
            fragments = new ArrayList<>();

    }

    public void addFrament(Fragment fragment) {
        if (fragments != null)
            fragments.add(fragment.getClass());
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        try {
            return  (Fragment)fragments.get(position).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }
}
